import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:tianpu_edu/Classes/libs/tool_color_utils.dart';
import 'package:tianpu_edu/Classes/libs/tool_image_utils.dart';
import 'Home/VC/home_page.dart';
import 'My/VC/my_page.dart';
import 'Find/VC/FindPage.dart';
import 'libs/tool_http_request.dart';

class TabBarController extends StatefulWidget {
  @override
  _TabBarControllerState createState() => _TabBarControllerState();
}

class _TabBarControllerState extends State<TabBarController> {

  var _appBarTitles = ['首页', '学习', '我的'];

  List<StatefulWidget> _pageList = [
    HomePage(),
    FindPage(),
    MyPage(),
  ];

  var _tabIndex = 0;
  
  @override
  void initState() {
    super.initState();

    //初始化设置 LogUtil
    LogUtil.init(isDebug: true);
  }

  @override
  Widget build(BuildContext context) {

    //布局风格
    return ScreenUtilInit(
      designSize: Size(750,1334),//设计稿中设备的尺寸(单位随意,但在使用过程中必须保持一致)
        allowFontScaling: false,//设置字体大小是否根据系统的“字体大小”辅助选项来进行缩放
        builder: ()=> MaterialApp(
          builder: EasyLoading.init(),
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            // appBar: AppBar(
            //   centerTitle: true,
            //   title: Text(_appBarTitles[_tabIndex]),
            // ),
            body: IndexedStack(
              children: _pageList,
              index: _tabIndex,
            ),
            bottomNavigationBar: BottomNavigationBar(
              items: [
                BottomNavigationBarItem(icon: loadAssetImage('icon_my'), label: _appBarTitles[0],activeIcon:loadAssetImage('icon_my_s')),
                BottomNavigationBarItem(icon: loadAssetImage('icon_class'), label: _appBarTitles[1],activeIcon:loadAssetImage('icon_class_s')),
                BottomNavigationBarItem(icon: loadAssetImage('icon_ke'), label: _appBarTitles[2],activeIcon:loadAssetImage('icon_ke_s')),
              ],
              type: BottomNavigationBarType.fixed,
              selectedItemColor: mainColor,
              currentIndex: _tabIndex,
              iconSize: 24,
              onTap: (index){
                setState(() {
                  _tabIndex = index;
                });
              },
            ),
          ),

    ));
  }
}
